package com.dwd.org.service.impl;

import com.dwd.basic.service.IBaseService;
import com.dwd.basic.service.impl.BaseServiceImpl;
import com.dwd.org.mapper.EmployeeMapper;
import com.dwd.org.pojo.Employee;
import com.dwd.org.pojo.Shop;
import com.dwd.org.service.IShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Description: TODO
 * @Author 汶狄
 * @Date 2021/1/15 18:30
 * @Version 1.0
 */
@Service
public class ShopServiceImpl extends BaseServiceImpl<Shop> implements IShopService {
    @Autowired
    private EmployeeMapper employeeMapper;

    /**
     * 存储商家信息
     *
     * @param shop
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void settledIn(Shop shop) {
        //得到id，没有存储admin_id
        super.save(shop);
        //获取员工
        Employee admin = shop.getAdmin();
        //设置shop_id
        admin.setShop(shop);
        employeeMapper.save(admin);
        //修改商家得admin_id 之前为空
        super.update(shop);
    }
}
